home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 49.9 KB | 1,349 lines | [TEXT/MPS ] |
- // UPrinting.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UPRINTING__
- #define __UPRINTING__
-
- // MacApp
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include "UPrintHandler.h"
- #endif
-
- // Toolbox
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- // ANSI
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Constants for the print info resources
- //----------------------------------------------------------------------------------------
-
- const ResType kGXPrintInfoRsrcType = 'FJOB';
- const ResNumber kGXPrintInfoRsrcID = 128;
-
- const ResType kPrintInfoRsrcType = 'PREC';
- const ResNumber kPrintInfoRsrcID = 128;
-
- const ResType kAlternatePrintInfoRsrcType = 'PRNT';
- const ResNumber kAlternatePrintInfoRsrcID = 128;
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TDocument;
- class TView;
- class TPrintInfo;
-
- //----------------------------------------------------------------------------------------
- // Forward and external structures and pointers.
- //----------------------------------------------------------------------------------------
- //
- // These keep us from having to include any of the printing interfaces in our interface
- // Since these are blind pointers they should not ever have to change much
- //
- #if qGXPrinting
- struct gxPrivateJobRecord;
- typedef struct gxPrivateJobRecord *gxJob;
- #endif
-
- struct TPrint;
- typedef struct TPrint TPrint, *TPPrint, **THPrint;
-
- struct TPrPort;
- typedef struct TPrPort TPrPort, *TPPrPort;
-
- //----------------------------------------------------------------------------------------
- // Command constants: Printing-related command numbers which apply only when a view with a
- // non-NULL PrintHandler is in the target chain
- //----------------------------------------------------------------------------------------
-
- const CommandNumber cChangePrinterStyle = 192; // Command arising from user's making
- // changes in Page Setup... dialog
-
- const CommandNumber cShowBreaks = 201; // Show Page Breaks command
-
-
- //----------------------------------------------------------------------------------------
- // Alert rsrc IDs
- //----------------------------------------------------------------------------------------
-
- const ResNumber phSpoolPrintDialog = 257; // the dialog shown when printing a file
- // (a misnomer - not just when spooled)
-
- const ResNumber phFinderPrintDialog = 258; // the dialog shown when doing Finder
- // Printing; differs from prev. by
- // addition of a 'Cancel All Printing'
- // button
-
- const ResNumber phNoPages = 251; // The "No pages within requested range"
- // alert
-
- //----------------------------------------------------------------------------------------
- // Dialog rsrc IDs
- //----------------------------------------------------------------------------------------
-
- const ResNumber phWhichDoc = 261; // The "Preparing to print <docname>"
- // dialog used during Finder printing
-
-
- //----------------------------------------------------------------------------------------
- // Miscellaneous
- //----------------------------------------------------------------------------------------
-
- const short kUsualPages = SHRT_MAX; // For methods that take a pageNumber
- // argument, this value indicates a
- // request for a general setting rather
- // than a setting customized to one
- // particular page
-
- const ResNumber kPrintDriverName = -8192; // STR resource in System file which
- // contains name of the default printer
-
-
-
-
- //----------------------------------------------------------------------------------------
- // Common Ancestor for printjob objects from different print architectures (MacPrint, GX, etc)
- //----------------------------------------------------------------------------------------
-
- class TPrintInfo : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- TPrintInfo();
-
- virtual ~TPrintInfo();
-
- void IPrintInfo();
-
- virtual TObject* Clone();
- // Makes a copy of the printInfo
-
- virtual void ReadFrom(TStream* aStream);
- // Read the fHPrint from the stream
-
- virtual void SetFrom(TPrintInfo* jobToCopy);
- // copy settings from another job
-
- virtual long GetSize(Boolean asResource = TRUE);
- // return the number of bytes necessary to store the print handle
- // asResource lets you make a distinction in the storage type
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace); // Override
- // If the printer has changed then we're invalid
-
- virtual VRect GetPaperRect();
- // returns the paper's rect
-
- virtual VRect GetInkRect();
- // returns the imagable page's rect
-
- virtual CPoint GetDeviceRes();
- // returns the current device's resolution vertically and horizontally
-
- virtual void SetToDefault();
- // Set the print Info to the default state
-
- virtual Boolean IsSetToDefault();
- // Returns TRUE if this Matches the printer's default
-
- virtual void GetPrintPages(long& fromPage,
- long& toPage,
- long& minFromPage,
- long& maxToPage);
- // Returns the page range of the job to print
-
- virtual void SetPrintPages(long fromPage,
- long toPage,
- long minFromPage,
- long maxToPage);
- // Sets the page range of the job to print
-
- virtual long GetPrintCopies();
- // Returns the number of copies specified in the job
-
- virtual void SetPrintCopies(long numCopies);
- // Sets the number of copies specified in the job
-
- virtual void SetTargetPrinter(const FSSpec& targetPrinter);
- // Sets the target printer for a "drag print"
-
- virtual void SetSpoolFile(FSSpec& spoolFile);
- // Sets the location for the spool file
-
- virtual Boolean IsSpooling();
- // Returns TRUE if we are spooling and not just drafting straight to the printer
-
- virtual Boolean IsMatch(TPrintInfo* thePrintInfo);
- // Returns TRUE if thePrintInfo can be said to match. FALSE if they
- // don't match or it can't be determined without validating them.
- // thePrintInfo doesn't have to be Valid but 'this' must be Valid
- // if it is not waiting for a default call
-
- virtual void Open(TObject* byWhom = NULL);
- // Attempts to open the printer. Signals failure if an error occurs.
-
- virtual Boolean IsOpen();
- // Returns TRUE if the printer is open.
-
- virtual void Close(TObject* byWhom = NULL);
- // Closes the Printer. DOES NOT signal failure if an error
- // occurs, only reports it to the debug window.
-
- Boolean IsDefaultForPrinter(TPrintInfo* thePrintInfo);
- // Returns TRUE if thePrintInfo matches the default for this printer.
-
- virtual OSErr GetError();
- // Return any current printing error.
-
- virtual void SetError(OSErr err);
- // Set the current printing error.
-
- virtual void ClearError();
- // Clear any current printing error.
-
- virtual Boolean ChkPrintErr(OSErr& err,
- Boolean& ranOutOfSpace);
-
- virtual void StartJob(const CStr255& ,
- long );
- // Start a printing job.
-
- virtual GrafPtr GetJobPort();
- // Returns the port that the job is printing to
-
- virtual void FinishJob();
- // Completes a printing job.
-
- virtual void StartPage(long );
- // Start a page.
-
- virtual void FinishPage();
- // Finish a page.
-
- virtual void JobMerge(TPrintInfo* mergeFrom);
- // Validate and Merge the job info from the source job onto the
- // destination job and Validate the result
-
- virtual TPrintInfo* GetDefaultPrintInfo();
- // Returns THE default TPrintInfo. Creating it first, if neccessary
-
- virtual Boolean CallJobDialog();
- // Calls PrJobDialog.
-
- virtual Boolean CallStyleDialog();
- // Calls PrStlDialog.
-
- virtual Boolean CallPrValidate();
- // Validates the printInfo.
-
- virtual void CallPrintDefault();
- // Calls PrintDefault.
-
- virtual Boolean CallPrPicFile(OSErr& err);
- // Calls PrPicFile.
-
- virtual void Invalidate();
- // Mark as invalid and issue a changed message
-
- virtual void Update();
- // Check if the target printer has changed and inform dependents if necessary
- // Ensures that the print info is current and valid
-
- void GetMaxSquareResolution(Fixed& hRes, Fixed& vRes);
- // Return the maximum square resolution supported by the printer
-
- void SetResolution(Fixed hRes, Fixed vRes);
- // Sets the printer to use the supplied resolution
-
- void MaximizeResolution();
- // Sets the printer to use the maximum square resolution
-
- inline Boolean IsValid()
- { return fIsValid; }
- // return the fIsValid flag
-
- inline Boolean NeedsDefault()
- { return fNeedsDefault; }
- // return the fNeedsDefault flag
-
- virtual void PosePrintDialog(const CStr255& docName, CommandNumber aCommandNumber);
- // Put up the 'Printing in Progress' dialog ( if applicable )
-
- virtual void BanishPrintDialog();
- // Get rid of the print dialog.
-
- virtual void ShowDocBeingPrinted(const CStr255& docName, Boolean entering);
- // Put up (or remove) a window whose title is the document's title, because the
- // Print Manager gets the document title from the front window.
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- Boolean fIsValid; // true if the print record is valid
- // because it's been validated OR
- // is the result of a setup dialog or sumthin'.
- Boolean fNeedsDefault; // true if the print record is valid
- };
-
-
- #if qGXPrinting
- //----------------------------------------------------------------------------------------
- // Encapsulates the the gxJob, etc for GX printing
- //----------------------------------------------------------------------------------------
-
- struct MySpoolDataRec
- {
- gxRectangle pageArea; // Page rectangle.
- gxViewPort printViewPort; // ViewPort we're printing with.
- };
-
- class TGXJob : public TPrintInfo
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TGXJob();
-
- virtual ~TGXJob();
-
- void IGXJob(gxJob itsgxJob=NULL, Boolean isValid=FALSE);
- // If itsgxJob is NULL the default job is retrieved from itsPrintMgr.
- // If itsPrintMgr is NULL the gDefaultPrinter will be used.
-
- virtual TObject* Clone();
- // Makes a copy of the printInfo
-
- virtual void ReadFrom(TStream* aStream);
- // Read the gxJob from the stream
-
- virtual void ConvertFrom(TStream* aStream);
- // Read the THPrint from the stream
-
- virtual void WriteTo(TStream* aStream);
- // Write the fHPrint to the stream
-
- virtual void SetFrom(TPrintInfo* jobToCopy);
- // copy settings from another job
-
- void SetFrom(gxJob jobToCopy, Boolean isValid = FALSE,
- Boolean needsDefault = FALSE);
- // copy settings from another gxJob
- // set IsValid TRUE if the handle is known to be valid
-
- virtual long GetSize(Boolean asResource = TRUE);
- // return the number of bytes necessary to store the print handle
- // asResource lets you make a distinction in the storage type
-
- static pascal OSErr GetSizeHelper (long size, void *data, void *refCon);
- // Helps the GetSize function by counting the number of bytes in GXFlattenJob
-
- virtual VRect GetPaperRect();
- // returns the paper's rect
-
- virtual VRect GetInkRect();
- // returns the imagable page's rect
-
- virtual CPoint GetDeviceRes();
- // returns the current device's resolution vertically and horizontally
-
- virtual void SetToDefault();
- // Set the print Info to the default state
-
- virtual Boolean IsSetToDefault();
- // Returns TRUE if this Matches the printer's default
-
- virtual void GetPrintPages(long& fromPage,
- long& toPage,
- long& minFromPage,
- long& maxToPage);
- // Returns the page range of the job to print
-
- virtual void SetPrintPages(long fromPage,
- long toPage,
- long minFromPage,
- long maxToPage);
- // Sets the page range of the job to print
-
- virtual long GetPrintCopies();
- // Returns the number of copies specified in the job
-
- virtual void SetPrintCopies(long numCopies);
- // Sets the number of copies specified in the job
-
- virtual void SetTargetPrinter(const FSSpec& targetPrinter);
- // Sets the target printer for a "drag print"
-
- Boolean IsDefaultForPrinter(TPrintInfo* thePrintInfo);
- // Returns TRUE if thePrintInfo matches the default for this printer.
-
- virtual OSErr GetError();
- // Return any current printing error.
-
- virtual void SetError(OSErr err);
- // Set the current printing error.
-
- virtual void StartJob(const CStr255& ,
- long );
- // Start a printing job.
-
- virtual GrafPtr GetJobPort();
- // Returns the port that the job is printing to
-
- virtual void FinishJob();
- // Completes a printing job.
-
- virtual void StartPage(long );
- // Start a page.
-
- virtual void FinishPage();
- // Finish a page.
-
- virtual void JobMerge(TPrintInfo* mergeFrom);
- // Validate and Merge the job info from the source job onto the
- // destination job and Validate the result
-
- virtual Boolean CallJobDialog();
- // Calls the job dialog.
-
- virtual Boolean CallStyleDialog();
- // Calls the setup dialog.
-
- virtual Boolean CallPrValidate();
- // Validates the printInfo.
-
- virtual void CallPrintDefault();
- // Calls PrintDefault.
-
- virtual void Update();
- // Check if the target printer has changed and inform dependents if necessary
- // Ensures that the print info is current and valid
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace); // Override
- // Check for printer driver changes on mAboutToLoseContro/mRegainControl
-
- void GetMaxSquareResolution(Fixed& hRes, Fixed& vRes);
- // Return the maximum square resolution supported by the printer
-
- void SetResolution(Fixed hRes, Fixed vRes);
- // Sets the printer to use the supplied resolution
-
- protected:
- gxJob GetgxJob();
- // Returns the fgxJob after Validation
-
- gxJob GetRawgxJob();
- // Returns the fgxJob without Validation
-
- void AdoptJob(gxJob itsgxJob);
- // call to adopt a job that's new to this info
-
- //----------------------------------------------------------------------------------------
- // static member functions
- //----------------------------------------------------------------------------------------
- protected:
-
- // These "C++" calling convention routines will be called via UPPs
- #if defined(__MWERKS__) && !(__POWERPC__ || __CFM68K__)
- # pragma d0_pointers on
- #endif
- static OSErr PrintingEventOverride(EventRecord* anEvent, Boolean filterEvent);
-
- static OSErr MyPrintAShape(gxShape currentShape, long refCon);
- // MyPrintAShape - This is a spool proc. for the translator
- // routines. In this routine, we simply draw each shape
- // we're passed (printing it). You could also capture each
- // shape into one gxPicture shape, and then do one draw of
- // that afterwards.
- #if defined(__MWERKS__) && !(__POWERPC__ || __CFM68K__)
- # pragma d0_pointers reset
- #endif
-
- static pascal OSErr MyUnflattenFunction(long size, void *data, void *refCon);
- // MyUnflattenFunction - This proc will get called when unflattening
- // a gxjob.
-
- static pascal OSErr MyFlattenFunction(long size, void *data, void *refCon);
- // MyFlattenFunction - This proc will get called when flattening
- // a gxjob.
-
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- gxJob fgxJob; // Default, validated job
- gxViewPort fPrintViewPort; // ViewPort for printing
-
- CGrafPort fQDPortRec; // Printer Port in use during printing
- CGrafPtr fQDPort; // Printer Port in use during printing
- MySpoolDataRec fSpoolData; // area to pass stuff to the PrintAShape routine
- };
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Encapsulates the THPrint for MacPrint printing
- //----------------------------------------------------------------------------------------
-
-
- //----------------------------------------------------------------------------------------
- // Manage entrance and exit from MacPrint
- //----------------------------------------------------------------------------------------
-
- class CInMacPrint
- {
- protected:
- void* operator new(size_t size); // prohibit "new CInMacPrint"
- void operator delete(void* obj); // avoid compiler warnings
-
- public:
- CInMacPrint(TPrintInfo* itsPrintinfo = NULL, TObject* byWhom = NULL, Boolean active=TRUE);
- // Puts us in the context of MacPrint.
- // if itsPrintMgr is NULL use the gDefaultPrinter
- // if byWhom is NULL use itsPrintMgr
- // If active is FALSE, nothing happens.
-
- ~CInMacPrint();
- // Removes the MacPrint context removes the failure handler.
-
- void Cleanup();
-
- //----------------------------------------------------------------------------------------
- // static member functions
- //----------------------------------------------------------------------------------------
- static void CallCleanup(void* context);
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- FailInfo fFailInfo; // the failure record that references
- // the failure handling method
- TPrintInfo* fPrintInfo; // The TPrintInfo used by us
- TObject* fByWhom; // the object responsible for this
- short fResFile; // The CurResFile before opening the print shop
- Boolean fIsActive; // True if we are going to activate.
- Boolean fPrintShopOpened; // True if the print shoppe opened successfully
- };
-
-
- class TMacPrintJob : public TPrintInfo
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TMacPrintJob();
-
- virtual ~TMacPrintJob();
-
- void IMacPrintJob(THPrint itsHPrint = NULL, Boolean isValid = FALSE);
- // If itsHPrint is NULL the default HPrint is retrieved from gDefaultPrintMgr
-
- virtual TObject* Clone();
- // Makes a copy of the printInfo
-
- virtual void ReadFrom(TStream* aStream);
- // Read the fHPrint from the stream
-
- virtual void WriteTo(TStream* aStream);
- // Write the fHPrint to the stream
-
- virtual void SetFrom(TPrintInfo* jobToCopy);
- // copy settings from another job
-
- void SetFrom(THPrint hPrintToCopy, Boolean isValid = FALSE,
- Boolean needsDefault = FALSE);
- // copy settings from another THPrint
- // set IsValid TRUE if the handle is known to be valid
-
- virtual long GetSize(Boolean asResource = TRUE);
- // return the number of bytes necessary to store the print handle
- // asResource lets you make a distinction in the storage type
-
- virtual VRect GetPaperRect();
- // returns the paper's rect
-
- virtual VRect GetInkRect();
- // returns the imagable page's rect
-
- virtual CPoint GetDeviceRes();
- // returns the current device's resolution vertically and horizontally
-
- virtual void SetToDefault();
- // Set the print Info to the default state
-
- virtual Boolean IsSetToDefault();
- // Returns TRUE if this Matches the printer's default
-
- virtual void GetPrintPages(long& fromPage,
- long& toPage,
- long& minFromPage,
- long& maxToPage);
- // Returns the page range of the job to print
-
- virtual void SetPrintPages(long fromPage,
- long toPage,
- long minFromPage,
- long maxToPage);
- // Sets the page range of the job to print
-
- virtual long GetPrintCopies();
- // Returns the number of copies specified in the job
-
- virtual void SetPrintCopies(long numCopies);
- // Sets the number of copies specified in the job
-
- virtual void SetSpoolFile(FSSpec& spoolFile);
- // Sets the location for the spool file
-
- virtual Boolean IsSpooling();
- // Returns TRUE if we are spooling and not just drafting straight to the printer
-
- virtual Boolean IsMatch(TPrintInfo* thePrintInfo);
- // Returns TRUE if thePrintInfo can be said to match. FALSE if they
- // don't match or it can't be determined without validating them.
- // thePrintInfo doesn't have to be Valid but 'this' must be Valid
- // if it is not waiting for a default call
-
- virtual void Open(TObject* byWhom = NULL);
- // Attempts to open the printer. Signals failure if an error occurs.
-
- virtual Boolean IsOpen();
- // Returns TRUE if the printer is open.
-
- virtual void Close(TObject* byWhom = NULL);
- // Closes the Printer. DOES NOT signal failure if an error
- // occurs, only reports it to the debug window.
-
- virtual OSErr GetError();
- // Return any current printing error.
-
- virtual void SetError(OSErr err);
- // Set the current printing error.
-
- virtual void StartJob(const CStr255& ,
- long );
- // Start a printing job.
-
- virtual GrafPtr GetJobPort();
- // Returns the port that the job is printing to
-
- virtual void FinishJob();
- // Completes a printing job.
-
- virtual void StartPage(long );
- // Start a page.
-
- virtual void FinishPage();
- // Finish a page.
-
- virtual void JobMerge(TPrintInfo* mergeFrom);
- // Validate and Merge the job info from the source job onto the
- // destination job and Validate the result
-
- virtual Boolean CallJobDialog();
- // Calls the job dialog.
-
- virtual Boolean CallStyleDialog();
- // Calls the setup dialog.
-
- virtual Boolean CallPrValidate();
- // Validates the printInfo.
-
- virtual void CallPrintDefault();
- // Calls PrintDefault.
-
- virtual Boolean CallPrPicFile(OSErr& err);
- // Calls PrPicFile.
-
- virtual void Update();
- // Check if the target printer has changed and inform dependents if necessary
- // Ensures that the print info is current and valid
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace); // Override
- // Check for printer driver changes on mAboutToLoseContro/mRegainControl
-
- void GetMaxSquareResolution(Fixed& hRes, Fixed& vRes);
- // Return the maximum square resolution supported by the printer
-
- void SetResolution(Fixed hRes, Fixed vRes);
- // Sets the printer to use the supplied resolution
-
- void MaximizeResolution();
- // Sets the printer to use the maximum square resolution
-
- virtual void DoPrintIdling();
- // Print job idle time handler. Handles events in the 'Print Dialogs' which give
- // the user 'Cancel', and, in the case of printing from the Finder, 'Cancel All
- // Printing.'
-
- virtual void PosePrintDialog(const CStr255& docName, CommandNumber aCommandNumber);
- // Put up the 'Printing in Progress' dialog ( if applicable )
-
- virtual void BanishPrintDialog();
- // Get rid of the print dialog.
-
- virtual void ShowDocBeingPrinted(const CStr255& docName, Boolean entering);
- // Put up (or remove) a window whose title is the document's title, because the
- // Print Manager gets the document title from the front window.
-
- protected:
- THPrint GetHPrint();
- // Returns the fHPrint after Validation
-
- THPrint GetRawHPrint();
- // Returns the fHPrint without Validation
-
- //----------------------------------------------------------------------------------------
- // static member functions
- //----------------------------------------------------------------------------------------
- public:
- static unsigned long CheckPrinterChangeLevel();
- // Determine if the user has selected a new printer type from the chooser.
-
- static void GetDriverName(CStr255& driverName);
- // Get the name of the current printer driver.
-
- static pascal void IdleProc();
- // Procedure whose address is passed to the print job for calling as often as
- // possible. Forwards to the DoPrintIdling method of the job's print handler.
- // NOTE: this routine requires the pascal keyword because it is a Toolbox callback
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- CStr255 fCurrentDocTitle; // Name of the current document being printed
- DialogRef fPrintDialog; // Used for all printing-related dialogs.
- // ??? (shouldn't this really be a view
- // (or TDialogView if using UDialog)
-
- THPrint fHPrint; // The THPrint for this job
- long fMinFromPage; // The minimum page that can be printed (for this jobs document)
- long fMaxToPage; // The maximum page that can be printed (for this jobs document)
-
- unsigned long fPrinterChangeLevel; // increases every time the name change is noticed.
-
- static TPPrPort fQDPort; // Printer Port in use during printing
- static short fPrintShopOpens; // counter for balancing Open and Close
-
- static CStr255 fgLastPrinterName; // printer that we're pointing at
- static unsigned long fgPrinterChangeLevel; // increases every time the name change is noticed.
- };
-
-
- //----------------------------------------------------------------------------------------
- // TStdPrintHandler: Actually Implements all the features that were stubbed out in its
- // ancestor. Basic flow of control at print time: Print, Validate, For each page(
- // FocusOnBorder, DrawPageInterior, FocusOnBorder, AdornPage) are called.
- //----------------------------------------------------------------------------------------
-
- class TStdPrintHandler : public TPrintHandler
- {
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // Initialization/ Termination
- //------------------------------------------------------------------------------------
-
- TStdPrintHandler();
- // Constructor
-
- void IStdPrintHandler(TDocument* itsDocument = NULL,
- TView* itsView = NULL,
- Boolean itsHFixedSize = kFixedSize,
- Boolean itsVFixedSize = kFixedSize);
- // Initializes the printHandler and installs it in the view;
- // Uses the default TPrintInfo if itsPrintInfo is NULL
- // By default the pages are considered fixed size.
-
- virtual ~TStdPrintHandler();
- // If relevant, frees the PrintInfo record and does other cleanup before freeing
- // this
-
- virtual TObject* Clone(); // Override
- // calls Inherited::Clone and then clones owned objects
-
-
- //------------------------------------------------------------------------------------
- // Page Strips
- //------------------------------------------------------------------------------------
-
- virtual VPoint CalcPageStrips();
- // Recalculate the number of strips of pages in each dimension.
-
- virtual VPoint CalcViewPerPage();
- // Decide how much view (h and v) normally gets mapped into page interiors.
-
- virtual VCoordinate BreakFollowing(VHSelect vhs,
- VCoordinate previousBreak,
- Boolean& automatic);
- // Returns the location of the page break which follows the page break located at
- // 'previousBreak', in direction vhs; returns automatic = true if the page-break is
- // thought of as an 'automatic' rather than a 'manual' (user-specified) one. Note
- // that page-breaks in dimension 'v' are drawn as vertical lines, those in
- // dimension 'h' as horizontal lines. Generic support at present is only provided
- // for 'automatic' page breaks; the 'automatic' parameter in BreakFollowing is a
- // hook to allow clients to support manual page breaks as well
-
- virtual void GetBreakCoord(VHSelect vhs,
- long whichBreak,
- VCoordinate& loc);
- // Returns, in 'loc', the coordinate of the 'whichBreak-th' page break in
- // dimension vhs. For example, GetBreakCoord(v, 5, loc) will return, in 'loc', the
- // horizontal coordinate of the vertical line (page-break) which marks the
- // boundary the area of the view which will be mapped into the 4th vertical strip
- // of pages and the area of the view which will be mapped into the 5th vertical
- // strip of pages
-
- virtual VPoint PageToStrip(long pageNumber);
- // Returns the horizontal and vertical strip for the given page.
-
- virtual long StripToPage(VPoint pageStrip);
- // Returns the page number for the given page strip.
-
-
- //------------------------------------------------------------------------------------
- // General Utility
- //------------------------------------------------------------------------------------
-
- virtual CStr255 GetDocName();
- // Returns the name of the document being printed, for use in the print dialog.
-
- virtual long MaxPageNumber();
- // Returns the highest page number which would be printed if the user requested
- // that all pages be printed.
-
- virtual void AdornPage();
- // Draw things on page # 'aPageNumber' which do not arise from the View but rather
- // from page considerations; examples: Headers and Footers; page numbers; frames
- // drawn around inset text; row and column headers for spreadsheets.
-
- virtual void ChooseSpoolFile(FSSpec& theSpoolFile,
- long& pagesPerSubjob);
- // Select the filename and volume to use for spooling; default chooses empty
- // CString on vol 0, which results in MacPrint's automatically choosing the local
- // Boot volume
-
- virtual void DrawPageInterior();
- // Make the QuickDraw calls which will result in the 'Interior' of page #
- // 'aPageNumber' being drawn. The 'Interior' is those things on the page which
- // arise from drawing the View associated with the PrintHandler
-
- virtual Boolean Focus(); // override
- // Set up the GrafPort, clipping, etc., to its values prior to printing a view
-
- virtual void FocusOnBorder();
- // Set up GrafPort, clipping, etc., prior to calling AdornPage
-
- virtual void FocusOnInterior();
- // Set up the GrafPort, clipping, etc., prior to calling DrawPageInterior
-
- virtual long GetDefaultSubJobSize();
- // Return default subjob size: SHRT_MAX
-
- virtual CPoint GetQDOrigin(); // override
- // Overridden to return fQDOrigin.
-
- virtual VPoint GetViewToQDOffset();
- // Overridden to return fViewToQDOffset.
-
- virtual VPoint LocatePageInterior(long pageNumber);
- // Determine where to locate the top-left corner of the Interior of the given page
- // number
-
- virtual Boolean OneSubJob(long subjobFirstPage,
- long subjobLastPage,
- long minFromPage,
- long maxToPage,
- Boolean justSpool,
- Boolean partialJob,
- Boolean& ranOutOfSpace,
- long& lastPageTried);
- // Processes one subjob for printing. Where appropriate, a print job is divided
- // automatically into one or more 'subjobs', so that a long document can be
- // printed even if there is very limited spool space available on the disk. This
- // is a generalization of the 'spool-a-page/ print-a-page' technique.
- // TStdPrintHandler will use a subjob size as large as can be handled by current
- // conditions, and will only fall back to more subjobs, each of smaller size, if
- // it experiences problems running with a larger subjob size
- // Returns TRUE to proceed
-
- virtual Boolean Print(CommandNumber itsCommandNumber);
- // Carries out printing for the print handler.
- // Returns TRUE to proceed
-
- virtual void PrintPage(long aPageNumber);
- // Print the indicated page
-
- virtual void SetPage(long aPageNumber);
- // Forwards to TView::DoSetInterior and TView::DoSetPageOffset
-
- virtual void SetPageInterior(long pageNumber);
- // Responsible for installing the correct values into fPageAreas.theInterior,
- // representing the 'interior' of the page in View coordinates.
-
- virtual void SetPageOffset(const VPoint& coord);
- // Given the view-coordinate of the top-left-most CPoint of the view which is
- // mapped into the interior of this page, calculate and set the offset for the
- // print code.
-
-
- //------------------------------------------------------------------------------------
- // Formatting for printing and other Setup methods
- //------------------------------------------------------------------------------------
-
- virtual void Invalidate();
- // Mark as invalid and issue a changed message
-
- virtual void Update();
- // Recompute the projection model and notify views if it changed
-
- virtual void InstallMargins(const VRect& newMargins,
- Boolean areMinimalMargins);
- // Install the (possibly new) margins specified; if 'areMinimalMargins' is true,
- // then the minimal-margins scheme is used; in this scheme, margins are always
- // maintained at exactly the size necessary to have the page Interior coincide
- // exactly with the printable area of the page
-
- virtual void MarginsTooBig(VRect &margins);
- // called by InstallMargins if the passed-in margins are too big for the current paper.
- // On entry, margins is the bad margins, on exit are (presumably) good margins.
- // The default version of this routine sets the margins so that theInterior == theInk
-
- virtual void PrinterChanged();
- // After printer specifications have changed, absorb the new metrics and reformat
- // the view if necessary
-
- virtual void RedoPageBreaks();
- // Recalculate the page breaks
-
- virtual void Reset();
- // Reset print record to default
-
- virtual TPrintInfo* GetPrintInfo();
- // Returns the printinfo (fPrintInfo)
-
- virtual void SetDefaultPrintInfo();
- // Create a PrintInfo record and initialize it to default values
-
- virtual void SetPrintExtent();
- // Sets the part of the print handler's view that is printed by this print
- // handler, by calling the view's GetPrintExtent.
-
- virtual void SetMargins();
- // Install the desired page margins
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace);
- // If the printer/printInfo has changed then we're invalid
-
- //------------------------------------------------------------------------------------
- // Scripting Support
- //------------------------------------------------------------------------------------
-
- virtual Boolean DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply); // override
- // Handle the print apple event
-
- //------------------------------------------------------------------------------------
- // Menu Commands
- //------------------------------------------------------------------------------------
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);
- // Handles 'show page breaks', among others
-
- virtual Boolean DoPrintCommand(CommandNumber aCommandNumber);
- // called by DoMenuCommand, handles posting the print command, returns true if
- // handled
-
- virtual void DoSetupMenus();
- // Sets up menus for 'show page breaks' and company
-
- virtual void DoSetupPrintMenus();
- // called by DoSetupMenus, sets up the print menus
-
-
- //------------------------------------------------------------------------------------
- // Finder Printing
- //------------------------------------------------------------------------------------
-
- virtual Boolean SetupForFinder(CommandNumber aCommandNumber);
- // Sets up the print record for finder printing. If fFinderPageSetup is true, then
- // PosePageSetupDialog is called. If fFinderJobDialog is true, then PoseJobDialog
- // is called. Otherwise, prJobMerge is called to merge the job record from the
-
- virtual Boolean SetupPrintOne(CommandNumber aCommandNumber);
- // Sets up the print record for a "print one" type of operation, one where the
- // entire document or view is printed and no job dialog takes place. This is also
- // used for "drag printing". Returns true if we should proceed.
-
-
- //------------------------------------------------------------------------------------
- // Screen Feedback
- //-----------------------------------------------------------------------------------
-
- virtual void DrawPrintFeedback(const VRect& area);
- // Gateway to all screen feedback related to pagination issues
-
- virtual void DrawPageBreak(VHSelect vhs,
- long whichBreak,
- VCoordinate loc,
- Boolean automatic);
- // Draws a page break on the screen.
-
- virtual void InvalPageFeedback();
- // Invalidates all page-related screen feedback
-
- virtual Boolean ShowsOnScreen();
- // Returns true only if the printHandler has an fView which is in an open window.
-
-
- //------------------------------------------------------------------------------------
- // Dialogs relating to printing
- //------------------------------------------------------------------------------------
-
- virtual Boolean PoseJobDialog();
- // Pose the 'Print Job' dialog
-
- virtual Boolean PosePageSetupDialog(Boolean isUndoable);
- // Undertake the 'Page Setup' dialog; post a command object to be performed if
- // relevant. Returns TRUE if the user did not cancel.
-
- virtual Boolean ChkPrintErr(OSErr& err,
- Boolean& ranOutOfSpace);
- // Checks for a MacPrint error, specially handles one particular error (sets
- // return parameter 'ranOutOfSpace' if error code indicates disk-space problem
- // while saving a spool file).
- // Returns TRUE to proceed
-
- virtual Boolean PrintSpoolFile(OSErr& err);
- // If printing was spooled by the print-driver then this method will be called to
- // print the spooled image.
- // Returns TRUE to proceed
-
- virtual VRect GetPaperRect();
-
- virtual VRect GetInkRect();
-
- virtual VRect GetMarginsRect();
-
- virtual VRect GetInteriorRect();
-
- virtual VPoint GetViewPerPage();
-
- //----------------------------------------------------------------------------------------
- // member functions that are really stubs (finally fleshed out here)
- //----------------------------------------------------------------------------------------
-
- virtual void TerminateUPrinting();
- // Call to terminate the printing system
-
- virtual void PrepareForFinderPrinting(const FSSpec* targetPrinter);
- // call this to prepare for printing from the finder
- // if targetPrinter is non-NULL then it specifies a "drag print" target
-
- virtual void DispatcherIsAvailable();
- // MacApp calls this when the dispatcher has been created and initialized.
-
- virtual long GetSavePrintInfoSize(TPrintInfo* itsPrintInfo, TFile* itsFile, Boolean useRsrcFork = TRUE);
- // returns the number of bytes necessary to save the print info.
-
- virtual void SavePrintInfo(TPrintInfo* itsPrintInfo, TFile* itsFile, Boolean useRsrcFork = TRUE);
- // Saves the print info to the passed in file.
-
- virtual TPrintInfo* RestorePrintInfo(TFile* itsFile, Boolean useRsrcFork = TRUE);
- // Initializes the print info from the passed in file.
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- VRect fPrintExtent; // the part of the view's extent that is
- // to be printed by this print handler.
- // The default is the entire extent, but
- // it can be changed with the method
- // SetAreaToPrint.
-
- VRect fViewedRect; // The part of the view shown on the
- // "current" page. Set by SetPage.
-
- VPoint fViewToQDOffset; // the computed translation of coordinates
- // necessary to account for adjustment of large
- // views down to QD space. This is set in
- // FocusOnInterior.
-
- VPoint fPageStrips; // For printing a view which will take
- // more than one page to print, the view
- // is thought of as being divided up by
- // vertical and horizontal lines ('page
- // breaks') into a checkerboard of
- // 'pages'. A vertical column, one page
- // wide, of such pages is called a
- // 'vertical page strip', while a
- // horizontal row, one page high, of such
- // pages is called a 'horizontal page
- // strip'. The number of vertical page
- // strips is represented by fPageStrips.v,
- // and the number of horizontal page
- // strips is represented by fPageStrips.h
- // In a typical Word Processor
- // application, there is only one vertical
- // strip of pages, but many horizontal
- // 'strips', each one only one page wide.
- // In a graphical application, there may
- // be many vertical as well as horizontal
- // strips of pages. fPageStrips is
- // recomputed by method CalcPageStrips.
-
- VPoint fLastStrip; // The last strip printed.
-
- VPoint fLastBreak; // The coordinates of the last page break.
-
- CRect fQDRectToClipTo; // This the clip rectangle calculated in
- // FocusOnInterior and FocusOnBorder. We
- // use it in ::Focus when a view or subview
- // being printed needs to focus on its
- // superview.
-
- CPoint fQDOrigin; // the computed QD origin for the port to
- // account for the area being printed.
- // This is set in FocusOnInterior and
- // FocusOnBorder.
-
- TPrintInfo* fPrintInfo; // The print record encapsulated in an object
- // The Print Record may be shared among all
- // PrintHandlers in a document or may be
- // unique to each PrintHandler, depending on
- // the flag TDocument::fSharePrintInfo
-
- CommandNumber fPrintingCommand; // The command number that was used when
- // invoking some printing function. This
- // can be used to determine if we are
- // printing from the finder.
-
- long fStartPage; // the page number for the topleftmost
- // corner of the view. Normally 1, but can
- // be set to any positive value
-
- VHSelect fPageDirection; // Determines how page numbers are to
- // advance in a large view which is more
- // than one page wide and more than one
- // page high; v means page 2 is BELOW page
- // 1; h means it's to its RIGHT.
- // Irrelevant if the view is only one page
- // wide or only one page high
-
- Boolean fFixedSizePages[2]; // Indicates whether pages are fixed size
- // horizontally and vertically.
-
- Boolean fFinderSetup; // whether, during Finder Printing, the
- // 'Page Setup' dialog should be presented
- // to the user
-
- Boolean fFinderJobDialog; // whether, during Finder Printing, the
- // Print Job dialog should be presented to
- // the user (making it seem like Print...)
- // or not (making it seem like Print One)
-
- Boolean fMinimalMargins; // If true, page margins are maintained
- // such that exactly the complete
- // printable area of the page is used.
-
- Boolean fUseMaxResolution; // If true the printing device will be set to
- // the maximum resolution available.
- protected:
- //
- // Former PageAreas struct: metrics for printing
- //
- VRect fPaperRect; // physical page
- VRect fInkRect; // printable page
- VRect fMarginsRect; // top-left positive; bottom-right negative
- VRect fInteriorRect; // VRect into which view-subset is projected
-
-
- //
- // Other stuff
- //
- Boolean fIsValid; // TRUE if the current printer projection
- // is valid. Set to false when any component
- // of the calculation of the projection changes.
- };
-
- //----------------------------------------------------------------------------------------
- // TPrintCommand: Returned in response to a printing request. Doesn't actually do the
- // printing itself, but forwards to the appropriate handler.
- //----------------------------------------------------------------------------------------
-
- class TPrintCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TPrintCommand();
- //Constructor
- virtual ~TPrintCommand();
- // Destructor
-
- void IPrintCommand(CommandNumber itsCommandNumber,
- TStdPrintHandler* itsStdPrintHandler);
- // Initialize the PrintCommand procedurally
-
- virtual void DoIt();
- // Tell the print handler to print
-
- virtual TAppleEvent* MakeAppleEvent();
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- TStdPrintHandler* fStdPrintHandler; // the associated print handler
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TPrintStyleChangeCommand: Used to allow changes made by the user in the 'Page Setup...'
- // dialog to be undoable.
- //----------------------------------------------------------------------------------------
-
- class TPrintStyleChangeCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // Initialization and Termination
- //------------------------------------------------------------------------------------
-
- TPrintStyleChangeCommand();
- // Constructor
-
- void IPrintStyleChangeCommand(TStdPrintHandler* itsPrintHandler, Boolean isUndoable = TRUE);
- // Initializes the print style change command, makes a copy of the old print
- // handle and creates the new one.
- // Can be undone if isUndoable is true
-
- virtual ~TPrintStyleChangeCommand();
- // Disposes the old and new print handles.
-
- //------------------------------------------------------------------------------------
- // Command Execution
- //------------------------------------------------------------------------------------
-
- virtual void DoIt();
- // Sets the print handler's printinfo from the new printinfo.
-
- virtual void UndoIt();
- // Sets the print handler's printinfo from the old printinfo.
-
- virtual void SetupDependencies(); // Override
- // Overridden to make this command a dependent of its print handler's fView.
- // And a dependent of its print handler's fPrintMgr.
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace); // Override
- // If the print handler's fView is closed, commit this command
- // If the printer driver has changed behind our back, we can no longer be undone.
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- TStdPrintHandler* fStdPrintHandler; // Associated print handler.
-
- TPrintInfo* fOldPrintInfo; // The old print record, before the change.
-
- public:
- TPrintInfo* fNewPrintInfo; // The new print record, after the change.
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations
- //----------------------------------------------------------------------------------------
-
- extern PenState gBreaksPenState; // penState to used to draw page breaks
-
- extern Boolean gCancelAllPrinting; // set to true if during Finder Printing
- // user selects Cancel All
-
- extern VRect gStdPageMargins; // "Standard" left, top, right, bottom
- // page margins, in screen resolution -
- // one inch all round by default
-
- extern TPrintInfo* gFinderPrintInfo; // Used for finder printing, to do
- // PrJobMerge when printing more than one
- // document.
-
- extern TStdPrintHandler* gJobPrintHandler; // The Print Handler in use during
- // printing.
-
- extern TPrintInfo* gDefaultPrintInfo; // The default TPrintInfo used by the
- // application. Used if no TPrintInfo* is
- // supplied to IStdPrintHandler
- // (Usually the case)
-
- extern FSSpec gTargetPrinter; // The current printer target for a "drag print"
- #if qGXPrinting
- extern Boolean gUsingGXPrinting;
- #endif
- // TRUE if GX Printing has been initialized (when used)
-
- //----------------------------------------------------------------------------------------
- // Global function declarations
- //----------------------------------------------------------------------------------------
-
- extern void InitUPrinting();
- // Call once, at application start-up time. You can interrogate global variable
- // 'gCouldPrint' at any time to determine whether printing code is actually accessible
-
- extern TPrintInfo* NewTPrintInfo(Boolean isValid = FALSE);
- // The default print record is retrieved from itsPrintMgr.
-
- #endif
-